﻿using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V4.View;
using Android.Support.V4.App;
using System.Threading.Tasks;

namespace DemoOkami
{
	[Activity(Label = "BetaTest",  Theme = "@android:style/Theme.Holo.Light",Icon = "@drawable/ic_action_view_as_grid")]
    public class Activity1 : FragmentActivity
    {
		ProgressDialog progress;
		string strResult = string.Empty;
		string allow=string.Empty;


        protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate (bundle);

			allow = Intent.GetStringExtra ("allow") ?? "Data not available";
			string user = Intent.GetStringExtra ("user") ?? "Data not available";

			SetContentView (Resource.Layout.Main);
			ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
			ActionBar.Title = "User: " + user;

			var pager = FindViewById<ViewPager> (Resource.Id.pager);
			var adaptor = new GenericFragmentPagerAdaptor (SupportFragmentManager);


			tabWS objWsCon = new tabWS (this);
			objWsCon.GetTab (ref adaptor, progress);
			ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "TabWS"));

			if (allow=="1") {
				tabSettings objSetCon = new tabSettings (this);
				objSetCon.GetTab (ref adaptor);
				ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "Settings"));
			}


			adaptor.AddFragmentView ((i, v, b) => {
				var view = i.Inflate (Resource.Layout.tab, v, false);
				var sampleTextView = view.FindViewById<TextView> (Resource.Id.textView1);
				sampleTextView.Text = "This is more content";
				return view;
			}
			);
			ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "generic1"));

			adaptor.AddFragmentView ((i, v, b) => {
				var view = i.Inflate (Resource.Layout.tab, v, false);
				var sampleTextView = view.FindViewById<TextView> (Resource.Id.textView1);
				sampleTextView.Text = "This is more content";
				return view;
			}
			);
			ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "generic2"));

			adaptor.AddFragmentView ((i, v, b) => {
				var view = i.Inflate (Resource.Layout.tab, v, false);
				var sampleTextView = view.FindViewById<TextView> (Resource.Id.textView1);
				sampleTextView.Text = "This is more content";
				return view;
			}
			);
			ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "generic3"));

			adaptor.AddFragmentView ((i, v, b) => {
				var view = i.Inflate (Resource.Layout.tab, v, false);
				var sampleTextView = view.FindViewById<TextView> (Resource.Id.textView1);
				sampleTextView.Text = "This is more content";
				return view;
			}
			);
			ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "generic4"));

			adaptor.AddFragmentView ((i, v, b) => {
				var view = i.Inflate (Resource.Layout.tab, v, false);
				var sampleTextView = view.FindViewById<TextView> (Resource.Id.textView1);
				sampleTextView.Text = "This is more content";
				return view;
			}
			);
			ActionBar.AddTab (pager.GetViewPageTab (ActionBar, "generic5"));

			pager.Adapter = adaptor;
			pager.SetOnPageChangeListener (new ViewPageListenerForActionBar (ActionBar));

		}

		public override bool OnCreateOptionsMenu (IMenu menu)
		{
			var inflater = MenuInflater;
			inflater.Inflate(Resource.Menu.ActionBarMenu, menu);

			ActionBar.SetDisplayShowHomeEnabled(false);
			ActionBar.SetDisplayHomeAsUpEnabled(false);
			ActionBar.SetHomeButtonEnabled(false);
			ActionBar.SetDisplayShowTitleEnabled(true);
			//Hide menu items you dont require
			//menu.FindItem(Resource.Id.action_settings).SetVisible(false);

			return base.OnCreateOptionsMenu(menu);

		}

		Intent CreateIntent ()
		{  
			var sendPictureIntent = new Intent (Intent.ActionSend);
			sendPictureIntent.SetType ("image/*");
			var uri = Android.Net.Uri.FromFile (GetFileStreamPath ("Favourites.png"));          
			sendPictureIntent.PutExtra ("message","Be happy!! :)");
			return sendPictureIntent;
		}


		/// <summary>
		/// On Menu Item Click
		/// </summary>
		/// <param name="featureId">The feature Id</param>
		/// <param name="item">The item selected</param>
		/// <returns>boolean</returns>
		public override bool OnMenuItemSelected(int featureId, IMenuItem item)
		{
			switch (item.ItemId)
			{
			case Resource.Id.action_search:
				Toast.MakeText (this, "share", ToastLength.Short).Show ();
				StartActivity (CreateIntent ());
				break;
			case Resource.Id.action_settings:
				Toast.MakeText(this,":)",ToastLength.Short).Show();
				break;
			case Resource.Id.action_settings2:
				Toast.MakeText(this,"Thanks!!",ToastLength.Short).Show();
				break;
			}
			return base.OnMenuItemSelected(featureId, item);
		}



	

	}
}

